package mo.offer_special;

public class L034 {

    public boolean isAlienSorted(String[] words, String order) {
        for (int i = 0; i < words.length - 1; i++) {
            String word1 = words[i];
            String word2 = words[i+1];
            int length2 = word2.length();
            for (int j = 0; j < word1.length(); j++) {
                if (j >= length2) {
                    if (word1.substring(0, j).equals(word2)) {
                        return false;
                    }
                    break;
                }
                if (order.indexOf(word1.charAt(j)) > order.indexOf(word2.charAt(j))) {
                    return false;
                }
                if (order.indexOf(word1.charAt(j)) < order.indexOf(word2.charAt(j))) {
                    break;
                }
            }
        }
        return true;
    }


}
